package test.testList;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

public class ListToExcel {

    public static void exportExcel(List<String> list,String outPath) throws Exception{
        if(CollectionUtils.isEmpty(list)){
            throw new RuntimeException("传入的list不能为空");
        }
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.getSheet("路径");
        for (int i = 0; i < list.size(); i++) {
            XSSFRow row = sheet.getRow(i);
            XSSFCell cell = row.getCell(0);
            cell.setCellValue(list.get(i));
        }

        FileOutputStream out = new FileOutputStream(new File(outPath));

        workbook.write(out);

        out.close();

    }
}
